<template>
  <div class="execution">
    <basic-container>
      <div class="searchBox">
        <el-form ref="form" :model="formData" label-width="80px" size="mini">
          <el-row :gutter="20">
            <el-col :span="8"
              ><div>
                <el-form-item label="预约日期">
                  <el-date-picker
                    v-model="formData.dateArr"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  >
                  </el-date-picker>
                </el-form-item></div
            ></el-col>

            <el-col :span="8"
              ><div>
                <el-form-item label="公司名称">
                  <el-input v-model="formData.companyName"></el-input>
                </el-form-item></div
            ></el-col>
            <el-col :span="8"
              ><div>
                <el-form-item label="联系方式">
                  <el-input v-model="formData.linkPhone"></el-input>
                </el-form-item></div
            ></el-col>
            <el-col :span="8"
              ><div>
                <el-form-item label="订单状态">
                  <el-select
                    v-model="formData.orderStatus"
                    placeholder="请选择缴费状态"
                  >
                    <el-option
                      v-for="(item, index) in statusList"
                      :key="index"
                      :label="item.dictName"
                      :value="item.dictValue"
                    ></el-option>
                  </el-select>
                </el-form-item></div
            ></el-col>
            <el-col :span="8"
              ><div>
                <el-button size="mini" type="primary">查询</el-button>
                <el-button size="mini">重置</el-button>
                <el-button size="mini">导出</el-button>
              </div></el-col
            >
          </el-row>
        </el-form>
      </div>
      <div class="tableBox">
        <el-table
          :data="tableData"
          style="width: 100%"
          stripe
          border
          :header-cell-style="{ background: '#409EFF', color: '#FFFFFF' }"
        >
          <el-table-column label="预约单号" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.orderNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column label="公司名称" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.companyName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.linkMan }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系方式" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.linkPhone }}</span>
            </template>
          </el-table-column>
          <el-table-column label="预约时间" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.createTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="状态"
            show-overflow-tooltip
            :formatter="$_formatStatus"
            prop="orderStatus"
          >
          </el-table-column>
          <el-table-column label="操作" width="145px">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="doDetail(scope.row)"
                >查看</el-button
              >

              <el-button
                size="mini"
                v-if="scope.row.orderStatus == 2"
                type="success"
                @click="doDelete(scope.row)"
                >接单</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="fenyeBox">
        <el-pagination
          :hide-on-single-page="false"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="perPage"
          layout="prev, pager, next, total,jumper"
          :total="totalNumber"
        ></el-pagination>
      </div>
    </basic-container>
    <order-detail
      :id="orderId"
      :visible="dialogVisible"
      @on-close="handleClose()"
    ></order-detail>
  </div>
</template>
<script>
import * as meeting from "@/api/meeting/meeting.js";
import orderDetail from "./detail.vue";
export default {
  components: {
    orderDetail,
  },
  data() {
    return {
      dialogTitle: "订单详情",
      dialogVisible: false,
      activeName: "1",
      orderId: "",
      //分页数据
      nowPage: 1,
      perPage: 10,
      currentPage: 1,
      PageCount: 0,
      totalNumber: 0,
      formData: {
        orderStatus: "",
        dateArr: [],
        companyName: "",
        linkPhone: "",
      },

      tableData: [],
      statusList: [
        {
          dictValue: -1,
          dictName: "已驳回",
        },
        {
          dictValue: 1,
          dictName: "待支付",
        },
        {
          dictValue: 2,
          dictName: "已支付",
        },
        {
          dictValue: 3,
          dictName: "待定价",
        },
        {
          dictValue: 4,
          dictName: "已接单",
        },
      ],
    };
  },
  mounted() {
    this.findMeetOrderAdminPage();
  },
  methods: {
    doDetail(obj) {
      this.orderId = obj.id;
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
      this.findMeetOrderAdminPage();
    },
    doDelete(obj) {
      let that = this;
      this.$confirm("请确认是否接单", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = {
            id: obj.id,
          };
          meeting
            .takeMeetOrderAdmin(data)
            .then((res) => {
              this.$message({
                type: "success",
                message: "接单成功!",
              });
              this.findMeetOrderAdminPage();
            })
            .catch((err) => {});
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消接单",
          });
        });
    },
    findMeetOrderAdminPage() {
      let data = {
        page: this.nowPage,
        pageSize: this.perPage,
        companyName: this.formData.carNumber,
        BPayDate: this.formData.dateArr[0],
        EPayDate: this.formData.dateArr[1],
        linkPhone: this.formData.linkPhone,
        orderStatus: this.formData.orderStatus,
      };
      meeting
        .findSiteOrderAdminPage(data)
        .then((res) => {
          console.log(res);
          this.tableData = [];
          let tempList = res.data.data.records;
          this.totalNumber = res.data.data.total;
          this.currentPage = res.data.data.current;
          for (let i = 0; i < tempList.length; i++) {
            let tempObj = {};
            tempObj = tempList[i];
            this.tableData.push(tempObj);
          }
        })
        .catch((err) => {});
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    $_formatStatus(row, column, cellValue) {
      if (cellValue) {
        let _types = this.statusList || [];
        let _obj =
          _types.find((value, index) => {
            return value.dictValue === cellValue;
          }) || {};
        return _obj.dictName || "";
      } else {
        return "/";
      }
    },
    handleCurrentChange(val) {
      this.nowPage = val;
      this.findMeetOrderAdminPage();
    },
  },
};
</script>
<style scoped>
.repairList {
  margin: 0 auto;
  padding: 16px;
}
.searchBox >>> .el-range-editor--mini.el-input__inner {
  width: 100%;
}
.searchBox >>> .el-select {
  width: 100%;
}
.searchBox >>> .el-date-editor.el-input,
.searchBox >>> .el-date-editor.el-input__inner {
  width: 100%;
}
.searchBox >>> .el-date-editor .el-range-separator {
  width: 30px;
}
.addBtnBox {
  text-align: left;
}
.repairTable {
  margin-top: 20px;
}
.fenyeBox {
  margin-top: 20px;
  text-align: right;
}
.tableBox >>> .el-table td,
.tableBox >>> .el-table th {
  text-align: center;
}
</style>
